{ pkgs, inputs, ... }: {
  imports = [
#   inputs.nixvim.nixosModules.nixvim
    inputs.nixvim.homeManagerModules.nixvim
  ];

  programs.nixvim = {
    enable = true;
    package = pkgs.neovim-unwrapped;

    options = {
      number = true;
      wrap = true;
      relativenumber = true;
      tabstop = 4;
      shiftwidth = 4;
      expandtab = true;
      laststatus = 3;
      termguicolors = true;
    };
    colorschemes = {
      catppuccin = {
        enable = true;
        flavour = "mocha";
      };
    };

    globals = {
      mapleader = " ";
    };

    maps = {
      normal = {
        # switch between buffers
        "<TAB>" = {
          action = ":bnext<CR>";
          noremap = true;
          silent = true;
        };
        "<S-TAB>" = {
          action = ":bprev<CR>";
          noremap = true;
          silent = true;
        };
        "<C-N>" = {
          action = ":NvimTreeToggle<CR>";
          noremap = true;
          silent = true;
        };
        "<C-b>" = {
          action = ":NvimTreeFocus<CR>";
          noremap = true;
          silent = true;
        };
        "tt" = {
          action = ":ToggleTerm direction=float<CR>";
          noremap = true;
          silent = true;
        };
        "<leader><space>" = {
          action = ":Telescope<CR>";
          noremap = true;
          silent = true;
        };
        "ff" = {
          action = ":Telescope find_files<CR>";
          noremap = true;
          silent = true;
        };
      };
    };

    plugins = {
      notify = {
        enable = true;
      };
      noice = {
        enable = true;
      };
      bufferline = {
        enable = true;
      };
      toggleterm = {
        enable = true;
      };
      comment-nvim = {
        enable = true;
      };
      cursorline = {
        enable = true;
        cursorline = {
          enable = true;
          number = true;
          timeout = 0;
        };
      };
      nvim-autopairs = {
        enable = true;
      };
      nvim-tree = {
        enable = true;
      };
      telescope = {
        enable = true;
      };
      nix = {
        enable = true;
      };
      treesitter = {
        enable = true;
        ensureInstalled = [ "rust" "nix" "norg" "norg_meta" "bash" ];
      };
      lsp = {
        enable = true;
        servers = {
          nil_ls.enable = true;
          pyright.enable = true;
        };
      };
      lspkind = {
        enable = true;
      };
      nvim-cmp = {
        enable = true;
        sources = [
          { name = "nvim_lsp"; }
        ];
        formatting.fields = [ "kind" "abbr" "menu" ];
      };
     #neorg = {
     #  enable = true;
     #  package = pkgs.vimPlugins.neorg;
     #  lazyLoading = false;
     #  modules = {
     #    "core.defaults" = {};                 
     #    "core.dirman" = {};                   
     #    "core.completion".config.engine = "nvim-cmp";
     #    "core.highlights" = {};               
     #    "core.highlightscore.keybinds" = {};  
     #    "core.integrations.treesitter" = {};  
     #    "core.mode" = {};                     
     #    "core.neorgcmd" = {};                 
     #    "core.pivot" = {};                    
     #    "core.promo" = {};                           
     #  };
     #};
    };

    extraPlugins = with pkgs.vimPlugins; [
      nvim-base16
    ];

    extraConfigLua = ''
      fn = vim.fn
      api = vim.api
      cmd = vim.cmd
      opt = vim.opt
      g = vim.g

      local modes = {
        ['n']    = 'NORMAL',
        ['no']   = 'NORMAL',
        ['nov']  = 'NORMAL',
        ['noV']  = 'NORMAL',
        ['no'] = 'NORMAL',
        ['niI']  = 'NORMAL',
        ['niR']  = 'NORMAL',
        ['niV']  = 'NORMAL',

        ['i']   = 'INSERT',
        ['ic']  = 'INSERT',
        ['ix']  = 'INSERT',
        ['s']   = 'INSERT',
        ['S']   = 'INSERT',

        ['v']   = 'VISUAL',
        ['V']   = 'VISUAL',
        ['']  = 'VISUAL',
        ['r']   = 'VISUAL',
        ['r?']  = 'VISUAL',

        ['c']   = 'TERMINAl',
        ['t']   = 'TERMINAL',
        ['!']   = 'TERMINAL',
        ['R']   = 'TERMINAL',
      }

      local icons = {
        ['typescript']         = ' ',
        ['python']             = ' ',
        ['java']               = ' ',
        ['html']               = ' ',
        ['css']                = ' ',
        ['scss']               = ' ',
        ['javascript']         = ' ',
        ['javascriptreact']    = ' ',
        ['markdown']           = ' ',
        ['sh']                 = ' ',
        ['zsh']                = ' ',
        ['vim']                = ' ',
        ['rust']               = ' ',
        ['cpp']                = ' ',
        ['c']                  = ' ',
        ['go']                 = ' ',
        ['lua']                = ' ',
        ['conf']               = ' ',
        ['haskel']             = ' ',
        ['ruby']               = ' ',
        ['txt']                = ' ',
        ['nix']                = ' '
      }

      local function color()
        local mode = api.nvim_get_mode().mode
        local mode_color = "%#StatusLine#"
        if mode == "n" then
          mode_color = "%#StatusNormal#"
        elseif mode == "i" or mode == "ic" then
          mode_color = "%#StatusInsert#"
        elseif mode == "v" or mode == "V" or mode == "" then
          mode_color = "%#StatusVisual#"
        elseif mode == "R" then
          mode_color = "%#StatusReplace#"
        elseif mode == "c" then
          mode_color = "%#StatusCommand#"
        elseif mode == "t" then
          mode_color = "%#StatusTerminal#"
        end
        return mode_color
      end

      local function branch()
        local cmd = io.popen('git branch --show-current 2>/dev/null')
        local branch = cmd:read("*l") or cmd:read("*a")
        cmd:close()
        if branch ~= "" then
          return string.format("   " .. branch)
        else
          return ""
        end
      end

      -- StatusLine Modes
      Status = function()
        return table.concat {
          color(), -- mode colors
          string.format("  %s ", modes[api.nvim_get_mode().mode]):upper(), -- mode
          "%#StatusActive#", -- middle color
          branch(),
          -- " %f ", -- file name
          "%=", -- right align
          string.format("%s", (icons[vim.bo.filetype] or "")),
          " %f ",
          color(), -- mode colors
          " %l:%c  ", -- line, column
        }
      end

      -- Execute statusline
      api.nvim_create_autocmd({"WinEnter", "BufEnter"}, {
        pattern = "*",
        command = "setlocal statusline=%!v:lua.Status()",
      })
      api.nvim_create_autocmd({"WinLeave", "BufLeave"}, {
        pattern = "*",
        command = "setlocal statusline=%#StatusLine#",
      })
      api.nvim_create_autocmd({"WinLeave", "BufLeave", "WinEnter", "BufEnter", "FileType"}, {
        pattern = {"NvimTree*", "terminal"},
        command = "setlocal statusline=%#StatusNormal#",
      })
    '';
  };
}
